package com.xinqi.modules.prepare.data.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareDataData;
import com.xinqi.modules.prepare.data.domain.PrepareDataEntity;
import com.xinqi.modules.prepare.data.dto.req.PrepareDataCreateDTO;
import com.xinqi.modules.prepare.data.dto.req.PrepareDataUpdateDTO;
import com.xinqi.modules.prepare.data.dto.rsp.PrepareDataResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区资料转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareDataConvert {
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDataEntity create(PrepareDataCreateDTO s);

    public abstract PrepareDataCreateDTO create(PrepareDataData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDataEntity update(PrepareDataUpdateDTO s, @MappingTarget PrepareDataEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDataEntity update(PrepareDataUpdateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareDataResultDTO convert(PrepareDataEntity s);

    public abstract PrepareDataData convert(PrepareDataResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareDataEntity copy(PrepareDataEntity entity, @MappingTarget PrepareDataEntity prepareDataEntity);
}
